package hk.m4s.lr.repair.test.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import hk.m4s.lr.repair.test.R;
import hk.m4s.lr.repair.test.model.JiangliModel;


/**
 * Created by qi.wang on 2017/3/16.
 */

public class CancleOrderListAdapter extends BaseAdapter {
    List<JiangliModel.ListBean> list = new ArrayList<JiangliModel.ListBean>();
    Context context;
    LayoutInflater inflater;
    public int flag=-1;
    public CancleOrderListAdapter(Context context, List<JiangliModel.ListBean> data) {
        this.context = context;
        this.list = data;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return 2;
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.list_item_jiangli_select, parent, false);
            holder.jiangli_name = (TextView) convertView.findViewById(R.id.jiangli_name);
            holder.jiangli_on = (Button) convertView.findViewById(R.id.jiangli_on);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.jiangli_on.setTag(position);
//        JiangliModel.ListBean deviceModel = list.get(position);
//        try {
//            holder.jiangli_name.setText(deviceModel.getText());
//            if (deviceModel.getState().equals("1")) {
//                holder.jiangli_on.setBackgroundResource(R.mipmap.checked_hover);
//            } else {
//                holder.jiangli_on.setBackgroundResource(R.mipmap.check);
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
        holder.jiangli_on.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int num = (Integer) v.getTag();
//                JiangliModel.ListBean deviceModel = list.get(num);
//                for (int i=0;i<list.size();i++){
//                    if(num==i){
//                        if(deviceModel.getState().equals("1")) {
//                            list.get(num).setState("2");
//                            notifyDataSetChanged();
//                        }else{
//                            list.get(i).setState("1");
//                            notifyDataSetChanged();
//                        }
//                    }else{
//                        list.get(i).setState("2");
//                        notifyDataSetChanged();
//                    }
//
//                }

            }
        });
        return convertView;
    }

    public static class ViewHolder {
        TextView jiangli_name;
        Button jiangli_on;
    }

}
